#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

struct myclass {
	bool operator() (string* i, string* j) 
	{ 
		if(i->length() < j->length())
			return true;
		if(i->length() > j->length())
			return false;
		return ( *i < *j ); 
	}
} cmp;

int main() {
	
	int N, i;
	string *pstr;
	vector<string*> str;
	vector<string*>::iterator str_it;
	cin >> N;
	
	for(i = 0; i < N; i++)
	{
		pstr = new string();
		cin >> *pstr;
		str.push_back(pstr);
	}
	
	sort(str.begin(), str.end(), cmp);
	
	for(str_it = str.begin(); str_it != str.end(); str_it++)	
	{
		cout << **str_it << endl;
	}
	
	return 0;
}
